package org.example.com.editor.workspace;

import com.fasterxml.jackson.databind.ObjectMapper; // 删掉！现在不直接依赖了
import org.example.com.editor.util.WorkspaceSerializer;

import java.io.File;
import java.io.IOException;

public class WorkspaceManager {
    private static final String STATE_FILE_PATH = System.getProperty("user.home") + "/.lab_editor/.editor_workspace";
    // 依赖接口（不再依赖具体的ObjectMapper）
    private final WorkspaceSerializer serializer;

    // 构造函数注入序列化实现（外部传入，解耦）
    public WorkspaceManager(WorkspaceSerializer serializer) {
        this.serializer = serializer;
    }

    public static String getStateFilePath() {
        return STATE_FILE_PATH;
    }

    public void saveMemento(WorkspaceState memento) throws IOException {
        File stateFile = new File(STATE_FILE_PATH);
        serializer.serialize(memento, stateFile);
    }

    public WorkspaceState loadMemento() throws IOException {
        File stateFile = new File(STATE_FILE_PATH);
        return serializer.deserialize(stateFile);
    }
}